/**
 * Created by sxing on 14-2-5.
 */
!function($) {
    "use strict";
    $.selectDialog = function(options) {
        var defaults = {
            title: "请选择",
            width: 700,
            height: 500,
            onEscape: function() {},
            selectBtnClass: "btn-success",
            cancelBtnClass: "btn",
            selectBtnLabel: "选择",
            cancelBtnLabel: "取消",
            selectedCallback: function(result){ console.log(result);}
        };
        var options = $.extend({}, defaults, options);
        var frameWin = null;
        var dialog = bootboxExt.dialogFrame({
            width: Number(options.width),
            height: Number(options.height),
            url: options.url,
            title: options.title,
            onEscape: options.onEscape,
            show: true,
            backdrop: true,
            animate: true,
            buttons: {
                success: {
                    label: options.selectBtnLabel,
                    className: options.selectBtnClass,
                    callback: function() {
                        if ($.isFunction(frameWin.doSelect)) {
                            var results = frameWin.doSelect();
                            options.selectedCallback(results);
                            return true;
                        }
                        return false;
                    }
                },
                cancel: {
                    label: options.cancelBtnLabel,
                    className: options.cancelBtnClass,
                    callback: function() {
                        return true;
                    }
                }
            }
        });
        dialog.on("shown.bs.modal", function(e) {

        });
        var frame = dialog.getFrame();
        frame.load(function(e) {
            frameWin = e.target.contentWindow;
        });
    };

}( window.jQuery);